package org.springblade.modules.notice.core.callback;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.utils.message.domain.SendRequest;
import org.springblade.modules.repair.entity.MessageCententCallbackRecord;
import org.springblade.modules.repair.service.IMessageCententCallbackRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class SmsCallback implements Callback {
	@Autowired
	private IMessageCententCallbackRecordService mccrService;

	@Override
	public void execute(SendRequest sendRequestParam, Map<String, Object> callbackData) {
		// 实现发送短信回调逻辑
		log.info("执行短信回调: 入参：{}， 回调数据：{}", JSONUtil.toJsonStr(sendRequestParam),JSONUtil.toJsonStr(callbackData));
		if(callbackData.containsKey("msgCode")){
			MessageCententCallbackRecord record = new MessageCententCallbackRecord();
			record.setPlanId(Long.valueOf(String.valueOf(callbackData.get("bizId"))));
			record.setElevatorId(Long.valueOf(String.valueOf(callbackData.get("elevatorId"))));
			record.setTenantId(String.valueOf(callbackData.get("tenantId")));
			record.setMsgCode(Integer.valueOf(String.valueOf(callbackData.get("msgCode"))));
			record.setCreateTime(DateUtil.date());
			mccrService.save(record);
		}
	}
}
